package org.spbsu.apco.common.utils;

import java.io.*;

/**
 * User: solozobov
 * Date: 12.01.13
 */

public class StreamUtils {

    private static final int BUFFER_LENGTH = 4096;

    public static long transferData(final InputStream in, final OutputStream out) throws IOException {
        final byte[] buffer = new byte[BUFFER_LENGTH];
        final InputStream bufferedIn = new BufferedInputStream(in);
        final OutputStream bufferedOut = new BufferedOutputStream(out);
        int read;
        long transfered = 0;
        while ((read = bufferedIn.read(buffer)) != -1) {
            bufferedOut.write(buffer, 0, read);
            transfered += read;
        }
        bufferedOut.flush();
        return transfered;
    }
}
